php get index of current item array_reduce

128

php get index of current item array_reduce -

$i = 0;
$p = array_reduce($array, function($output, $item) use (&$i, $array) {
   // use $i
   // do something with $item and/or $output
   if ($array[$i]) {
     // perform operation on $output
   }
   $i++; // increment $i
   return $output;
}, $initial);

Comments

Submit
0 Comments